package com.chenxi.controller;

import com.chenxi.client.IOAuth2Client;
import com.chenxi.client.IUserClient;
import com.chenxi.model.User;
import com.chenxi.service.UserServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HomeController extends BaseController {

    @Autowired
    private IUserClient userClient;
    @Autowired
    private IOAuth2Client OAuth2Client;

    @Autowired
    private OAuth2RestTemplate restTemplate;

    @Autowired
    private UserServiceI userService;

    @GetMapping(value = "/test")
    public String Test(){
        return "ssss";
    }

    @GetMapping(value = "/revoke_token")
    public String revokeToken(){
        System.out.println(restTemplate.getAccessToken().getValue());
        return OAuth2Client.revokeToken(restTemplate.getAccessToken().getValue());
    }

    @RequestMapping(value = "/user")
    public String getUserName(){

        return restTemplate.getAccessToken().getValue();
    }

    @RequestMapping(value = "/getUser")
    public User getUser(){
        return userClient.getUser();
    }
}
